package com.xuecheng.manage_media.controller;

import com.xuecheng.api.media.MediaUploadFolderMappingControllerApi;
import com.xuecheng.framework.domain.media.folder.FolderMappingNode;
import com.xuecheng.framework.domain.media.request.FolderMappingRequest;
import com.xuecheng.framework.model.response.CommonCode;
import com.xuecheng.framework.model.response.ResponseResult;
import com.xuecheng.manage_media.util.foldermapping.FolderMappingUtil;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * 上传文件的时候会指定存储位置, 这是映射的本地文件夹
 */
@RestController
@RequestMapping("/media/upload")
public class MediaUploadFolderMappingController implements MediaUploadFolderMappingControllerApi {

    @Resource
    FolderMappingUtil folderMappingUtil;
    /**
     * 映射视频上传文件夹路径
     * @return 映射的json
     */
    @GetMapping("/folderMapping")
    public FolderMappingNode getFolderMapping() {
        return folderMappingUtil.mapping();
    }

    /**
     * 删除一个空文件夹
     * @param folderMappingRequest 文件夹的路径参数
     * @return 结果
     */
    @Override
    @DeleteMapping("/folderDel")
    public ResponseResult delFolder(@RequestBody FolderMappingRequest folderMappingRequest) {
        boolean b = folderMappingUtil.delFolder(folderMappingRequest);
        if (b) {
            return new ResponseResult(CommonCode.SUCCESS);
        } else {
            return new ResponseResult(CommonCode.UNAUTHORISE);
        }
    }

    /**
     * 添加一个文件夹
     * @param folderMappingRequest 文件夹的路径参数
     * @return 结果
     */
    @PostMapping("/folderAdd")
    public ResponseResult addFolder(@RequestBody FolderMappingRequest folderMappingRequest) {
        boolean b = folderMappingUtil.addFolder(folderMappingRequest);
        if (b) {
            return new ResponseResult(CommonCode.SUCCESS);
        } else {
            return new ResponseResult(CommonCode.UNAUTHORISE);
        }
    }
}
